import axios from "axios";

const config = {
    baseURL: import.meta.env.VITE_BASE_URL,
    timeout: 5000,
}

class Service {
    instance: any;
    constructor(config) {
        this.instance = axios.create(config);
        this.interceptors()
    }

    interceptors() {
        this.instance.interceptors.request.use(config => {
            // config.headers['Authorization'] = `Bearer ${import.meta.env.VITE_APP_TOKEN}`;
            return config;
        }, error => {
            return Promise.reject(error);
        });

        this.instance.interceptors.response.use(response => {
            return response.data;
        }, error => {
            return Promise.reject(error);
        });
    }

    request(config) {
        return this.instance.request(config);
    }
    post(url, data) {
        return this.request({ url, method: 'post', data  });
    }
    get(url, params) {
        return this.request({ url, method: 'get', params });
    }

}

const service = new Service(config);
export default service;
